﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;
using Twi.COMMON.Core;

namespace Twi.Websites.Core.Controllers
{
    public class FileUploadController : Controller
    {
        //
        // GET: /FileUpload/

        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 使用Uploadify文件上传
        /// </summary>
        /// <returns></returns>
        public ActionResult UseUploadify()
        {
            return View();
        }

        /// <summary>
        /// 使用Uploadify文件上传处理方法
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public string UploadifyHandler()
        {
            TwiReturn twi = new TwiReturn();
            twi.hasRight = true;
            try
            {
                HttpPostedFileBase file = Request.Files["Filedata"];
                string fileDirectory = Server.MapPath("~/UploadFiles");
                if (!Directory.Exists(fileDirectory))
                {
                    Directory.CreateDirectory(fileDirectory);
                }
                string fileNewName = fileDirectory+"\\"+DateTime.Now.ToString("yyyyMMddHHmmssffff") + Path.GetExtension(file.FileName);
                file.SaveAs(fileNewName);
                twi.success = true;
                
                string realName = Request["FRealName"];
                string name = Request.Form["FName"];
            }
            catch (System.Exception ex)
            {
                twi.errors = ex.Message;
            }

            return JSSerialize.Serialize(twi);
        }
    }
}
